package StudyCode.summary.mycollection;

import java.util.ArrayList;
import java.util.List;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class SetDifferenceForCharArray {
	public static void main(String[] argv) {
		char[] charArr1 = new char[]{'w', 'w', 'w', 't', 'a', 'h', '1', '9', '8', '6', 'c', 'o', 'm'};
		char[] charArr2 = new char[]{'t', 'a', 'h', '1', '9', '8', '6', 'c', 'o', 'm'};
		System.out.println(java.util.Arrays.toString(setDifference(charArr1, charArr2)));
	}

	public static char[] setDifference(char[] charArr1, char[] charArr2) {
		List<Character> list1 = toList(charArr1);
		List<Character> list2 = toList(charArr2);
		for (Character charObj : list2) {
			list1.remove(charObj);
		}
		return toCharArray(list1);
	}

	private static List<Character> toList(char[] charArr) {
		assert charArr != null;
		List<Character> charList = new ArrayList<Character>();
		for (char ch : charArr) {
			charList.add(ch);
		}
		return charList;
	}

	private static char[] toCharArray(List<Character> charList) {
		if (charList == null || charList.isEmpty()) {
			return new char[0];
		}

		char[] charArr = new char[charList.size()];
		for (int index = 0; index < charList.size(); index++) {
			charArr[index] = charList.get(index);
		}
		return charArr;
	}
}
